﻿Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Graphics
Imports System.Collections.ObjectModel
Imports Runa.UI.Compoents

Namespace Global.Runa.UI.Controls

    Public Class ContentControl
        Inherits UIElementBase

        Protected _Content As UIElementBase
        Protected _ContentBounds As Rectangle
        Protected _ContentBoundsPercentage As Vector4

        Public Sub New(ByVal g As Game)
            MyBase.New(g)
        End Sub

        Public Sub New(ByVal Parent As UIElementBase)
            MyBase.New("", Parent)
            Me.Name = Me.GetType().Name & "_" & BytesToString(Guid.NewGuid().ToByteArray())
        End Sub

        Public Sub New(ByVal Name As String)
            MyBase.New(Name)
        End Sub

        Public Sub New(ByVal Name As String, ByVal Parent As UIElementBase)
            MyBase.New(Name, Parent)
        End Sub

        Public Overrides Sub Draw(ByVal SpriteBatch As SpriteBatch)
            If (Not Me.Content Is Nothing) Then
                Me.Content.Draw(SpriteBatch)
            End If
            MyBase.Draw(SpriteBatch)
        End Sub

        Public Overrides Sub Update(ByVal gameTime As GameTime)
            If (Not Me.Content Is Nothing) Then
                Me.Content.Update(gameTime)
            End If
            MyBase.Update(gameTime)
        End Sub

        Public Property Content As UIElementBase
            Get
                Return Me._Content
            End Get
            Set(ByVal value As UIElementBase)
                If (Not value Is Me._Content) Then
                    Me._Content = value
                    value.Parent = Me
                    value.DrawBounds = Me.ContentBounds
                End If
            End Set
        End Property

        Public Property ContentBounds As Rectangle
            Get
                Return Me._ContentBounds
            End Get
            Set(ByVal value As Rectangle)
                If (Me._ContentBounds <> value) Then
                    Me._ContentBounds = value
                    If (Not Me.Content Is Nothing) Then
                        Me.Content.DrawBounds = value
                    End If
                End If
            End Set
        End Property

        Public Property ContentBoundsPercentage As Vector4
            Get
                Return Me._ContentBoundsPercentage
            End Get
            Set(ByVal value As Vector4)
                If (Me._ContentBoundsPercentage <> value) Then
                    Me._ContentBoundsPercentage = value
                    Me.ContentBounds = New Rectangle((Me.AbsoluteBounds.X + CInt((Me.AbsoluteBounds.Width * value.X))), (Me.AbsoluteBounds.Y + CInt((Me.AbsoluteBounds.Height * value.Y))), CInt((Me.AbsoluteBounds.Width * value.Z)), CInt((Me.AbsoluteBounds.Height * value.W)))
                End If
            End Set
        End Property

    End Class

End Namespace